﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using KenLib.BusinessManager;
using DataInfo;

public partial class JOINT_frmJ_StaffRewPunInput : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        ((JOINT_MstPage_JOINT)this.Master).changeTitle("雇用情報登録");
        ((JOINT_MstPage_JOINT)this.Master).HideLiArea("input");
                       
        if (Session["ModeUpdate"] != null)// Session Update se lay mode Update tu trang frmJ_EmpbasicInfo cua link 語学力情報
        {
            this.CheckUpdate();
        }
        else
        {
            if (Session["IdEmp"] == null || Session["IdEmp"] == "")
            {
                Response.Redirect("frmJ_MCompManager.aspx");
            }
        }
        txt賞罰名.Focus();
        validate_txt賞罰名.ErrorMessage = GetError("ER00001");
        validate_txt賞罰年月日.ErrorMessage = GetError("ER00001");
        //validate_regular_txt賞罰年月日.ErrorMessage = "賞罰年月日" + GetError("ER00002");
        CustomValidator2.ErrorMessage = GetError("ER00002");
        validate_txt賞罰特記事項.ErrorMessage =  GetError("ER00001");
        validate_regular_txt賞罰特記事項.ErrorMessage = GetError("ER000012");
    }
    protected void btn_戻る_Click(object sender, EventArgs e)
    {
        if (Session["ModeUpdate"] != null)// Session Update se lay mode Update tu trang frmJ_EmpbasicInfo cua link 語学力情報
        {
            Response.Redirect("frmJ_EmpBasicInfo.aspx");
        }
        else
        {
            Response.Redirect("frmJ_StaffWorkSkillInput.aspx");
        }

    }
    protected void btn_次_Click(object sender, EventArgs e)
    {
        Response.Redirect("frmJ_StaffPhysicalExamInput.aspx");
    }
    protected void btn_登録_Click(object sender, EventArgs e)
    {
        if (Session["ModeUpdate"] != null)// Session Update se lay mode Update tu trang frmJ_EmpbasicInfo cua link 語学力情報
        {
            賞罰情報Manager frm = new 賞罰情報Manager();
            賞罰情報 obj = new 賞罰情報();
            obj.ID = 1; //Session ID se lay ID tu trang frmJ_EmpbasicInfo cua link 語学力情報
            obj.賞罰名 = HttpUtility.HtmlEncode(txt賞罰名.Text.Trim().ToString());
            obj.賞罰年月日 = DateTime.Parse(txt賞罰年月日.Text.ToString());
            obj.賞罰特記事項 = HttpUtility.HtmlEncode(txt賞罰特記事項.Text.ToString());
            frm.Update_frmJ_TraineeRewPunInput(obj);
            Response.Redirect("frmJ_EmpBasicInfo.aspx");
        }
        else
        {
            賞罰情報Manager frm = new 賞罰情報Manager();
            賞罰情報 obj = new 賞罰情報();
            obj.廃止区分 = 0;
            obj.賞罰名 = HttpUtility.HtmlEncode(txt賞罰名.Text.Trim().ToString());
            obj.賞罰年月日 = DateTime.Parse(txt賞罰年月日.Text.ToString());
            obj.賞罰特記事項 = HttpUtility.HtmlEncode(txt賞罰特記事項.Text.ToString());//.Replace("\n", "<br />"));
            obj.社員ID = Int32.Parse(Session["IdEmp"].ToString()); //1;// ID lay tu sesssion khi dang ky tu trang frmJ_StaffBasicInfoInput
            frm.Insert_frmJ_TraineeRewPunInput(obj);
            Response.Redirect("frmJ_StaffPhysicalExamInput.aspx");
        }
    }

    public void CheckUpdate()
    {
        
        btn_次.Enabled = false;
        賞罰情報Manager frm = new 賞罰情報Manager();
        DataTable dt = new DataTable();
        int ID = 1;// ID lay session tu tramg Emp_BasicInfo 
        dt = frm.Select_frmJ_StaffRewPunInput(ID);
        if (dt.Rows.Count > 0)
        {
            foreach (DataRow row in dt.Rows)
            {
                txt賞罰名.Text = row["賞罰名"].ToString();
                txt賞罰年月日.Text = row["賞罰年月日"].ToString();
                txt賞罰特記事項.Text = row["賞罰特記事項"].ToString();
            }
        }
    }
    protected void btn_リセット_Click(object sender, EventArgs e)
    {
        if (Session["ModeUpdate"] != null)
        {
            this.CheckUpdate();
        }
        else
        {
            Response.Redirect("frmJ_StaffRewPunInput.aspx");
        }
    }

    public String GetError(string errorid)
    {
        string error = "";
        Error er = new Error();
        er.ErrorID = errorid;
        ErrorManager frm_error = new ErrorManager();
        DataTable dt = frm_error.getError(er);
        if (dt.Rows.Count > 0)
        {
            return error = dt.Rows[0][2].ToString();
        }
        else
        {
            return error;
        }


    }
}
